package com.hc.util;

public class StringUtil {

    /**
     * 从 CamelCaseTestT 变成 camel_case_test_t
     *
     * @param camel 驼峰式
     * @return 下划线式
     */
    public static String camelCaseToUnderLine(String camel) {
        char[] carr = camel.toCharArray();
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(Character.toLowerCase(carr[0]));
        for (int i = 1; i < carr.length; i++) {
            char c = carr[i];
            if (c >= 65 && c <= 90) {
                stringBuilder.append('_');
                stringBuilder.append(Character.toLowerCase(c));
            } else {
                stringBuilder.append(c);
            }
        }
        return stringBuilder.toString();
    }
}
